import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../resource/ImagesConst";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { TilePanel } from "../equipment/TilePanel";
import { ScrollBarDirection } from "../../../../fl/controls/ScrollBarDirection";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { ExitRenderer } from "./itemRender/ExitRenderer";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { NPCRenderer } from "./itemRender/NPCRenderer";
import { BossRenderer } from "./itemRender/BossRenderer";
import { HotTransferRenderer } from "./itemRender/HotTransferRenderer";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { GTextFormat } from "../../../common/GTextFormat";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { ResFileConst } from "../../resource/ResFileConst";
import { SceneInfo } from "../../scene/map/SceneInfo";
import { MapFileUtil } from "../../scene/map/MapFileUtil";
import { Game } from "../../Game";
import { PassInfo } from "../../scene/player/info/PassInfo";
import { NPCInfo } from "../../model/NPCInfo";
import { BossRefreshInfo } from "../../model/BossRefreshInfo";
import { Log } from "../../../../com/gengine/debug/Log";
import { Cache } from "../../cache/Cache";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { BossRule } from "../../rules/BossRule";
import { DisplayUtil } from "../../../common/DisplayUtil";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { VIPUtil } from "../vip/VIPUtil";
import { GameMapUtil } from "../../scene/map/GameMapUtil";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
type int = number;
//class CurrentMapInfoPanel
    
    export  class CurrentMapInfoPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initUI();
            return;
        }

        protected initUI(): void
        {
            var loc1=null;
            this._bg = ResouceConst.getScaleBitmap(ImagesConst.WindowBg2);
            this._bg.width = 168;
            this._bg.height = 460;
            addChild(this._bg);
            this._hotTransferSp = ObjCreate.createSprite();
            this._hotTransferSp.y = 30;
            this.addChild(this._hotTransferSp);
            this._commonTransferSp = ObjCreate.createSprite();
            this._commonTransferSp.y = 30;
            this._hotTransferBtn = ObjCreate.createGButton(Language.getString(20163), 16, 9, 62, 22, this, "ButtonRed");
            this._hotTransferBtn.name = "hotTransferBtn";
            this._hotTransferBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onChangeHandler);
            this._commonTransferBtn = ObjCreate.createGButton(Language.getString(20164), 90, 8, 62, 23, this);
            this._commonTransferBtn.name = "commonTransferBtn";
            this._commonTransferBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onChangeHandler);
            this._exitList = new TilePanel();
            this._exitList.rowHeight = 20;
            this._exitList.columnWidth = 150;
            this._exitList.horizontalGap = 1;
            this._exitList.verticalGap = 0;
            this._exitList.direction = ScrollBarDirection.VERTICAL;
            this._exitList.scrollPolicy = ScrollPolicy.AUTO;
            this._exitList.setStyle("cellRenderer", ExitRenderer);
            this._exitList.setStyle("skin", new Object /* flash.display.Sprite */());
            this._exitList.selectable = false;
            ObjCreate.setObjAttri(this._exitList, 15, 34, 135, 60, this._commonTransferSp);
            this._line1 = GlobalClass.getBitmap(ImagesConst.Line);
            ObjCreate.setObjAttri(this._line1, -10, 98, 200, -1, this._commonTransferSp);
            this._npcList = new TilePanel();
            this._npcList.rowHeight = 20;
            this._npcList.columnWidth = 150;
            this._npcList.horizontalGap = 1;
            this._npcList.verticalGap = 0;
            this._npcList.direction = ScrollBarDirection.VERTICAL;
            this._npcList.scrollPolicy = ScrollPolicy.AUTO;
            this._npcList.setStyle("cellRenderer", NPCRenderer);
            this._npcList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._npcList.selectable = false;
            ObjCreate.setObjAttri(this._npcList, 15, 127, 135, 143, this._commonTransferSp);
            this._line2 = GlobalClass.getBitmap(ImagesConst.Line);
            ObjCreate.setObjAttri(this._line2, -10, 274, 200, -1, this._commonTransferSp);
            this._bossList = new TilePanel();
            this._bossList.rowHeight = 20;
            this._bossList.columnWidth = 150;
            this._bossList.horizontalGap = 1;
            this._bossList.verticalGap = 0;
            this._bossList.direction = ScrollBarDirection.VERTICAL;
            this._bossList.scrollPolicy = ScrollPolicy.AUTO;
            this._bossList.setStyle("cellRenderer", BossRenderer);
            this._bossList.setStyle("skin", new Object /* flash.display.Bitmap */());
            this._bossList.selectable = false;
            ObjCreate.setObjAttri(this._bossList, 15, 303, 135, 120, this._commonTransferSp);
            ObjCreate.createGBitmap(ImagesConst.MapUIWorldCenterWord, 10, 6, this._hotTransferSp);
            ObjCreate.createGBitmap(ImagesConst.MapUIBossWord, 10, 90, this._hotTransferSp);
            var loc2=0;
            while (loc2 < 6) 
            {
                loc1 = new HotTransferRenderer(loc2, GameDefConfig.instance.getItem("mapUIHotTransfer", loc2));
                if (loc2 != 0) 
                {
                    ObjCreate.setObjAttri(loc1, 10, 120 + (loc2 - 1) * 52, -1, -1, this._hotTransferSp);
                }
                else 
                {
                    ObjCreate.setObjAttri(loc1, 10, 38, -1, -1, this._hotTransferSp);
                }
                ++loc2;
            }
            var loc3=GlobalClass.getBitmap(ImagesConst.Line);
            ObjCreate.setObjAttri(loc3, 0, 372, 200, -1, this._hotTransferSp);
            this._autoCloseMap = ObjCreate.createCheckBox("", 10, 400, 255, 28, this._hotTransferSp);
            this._autoCloseMap.setStyle("textFormat", new GTextFormat(null, 12, GlobalStyle.color4Uint));
            this._autoCloseMap.label = Language.getString(20166);
            this._autoCloseMap.selected = true;
            this._autoCloseMap.addEventListener(flash.events.Event.CHANGE, this.onAutoCloseMapHandler);
            this._vipHangBtn = ObjCreate.createGButton(Language.getString(90327), 30, 379, 110, 25, this._hotTransferSp);
            this._vipHangBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onVipHangBtnClickHandler);
            this._vipHangBtn.name = "hang";
            LoaderHelp.addResCallBack(ResFileConst.mapUI, this.onMapUIResLoadedHandler);
            return;
        }

        protected onMapUIResLoadedHandler(): void
        {
            this._mapExitBitmap = GlobalClass.getBitmap(ImagesConst.MapUIExit);
            ObjCreate.setObjAttri(this._mapExitBitmap, 10, 8, -1, -1, this._commonTransferSp);
            this._mapNpcBitmap = GlobalClass.getBitmap(ImagesConst.MapUINpc);
            ObjCreate.setObjAttri(this._mapNpcBitmap, 10, 102, -1, -1, this._commonTransferSp);
            this._mapBossBitmap = GlobalClass.getBitmap(ImagesConst.MapUIMonster);
            ObjCreate.setObjAttri(this._mapBossBitmap, 10, 278, -1, -1, this._commonTransferSp);
            return;
        }

        public updateMap(): void
        {
            var sceneInfo: SceneInfo;

            var loc1;
            if (this._currentMapid == MapFileUtil.mapID) 
            {
                return;
            }
            this._currentMapid = MapFileUtil.mapID;
            sceneInfo = Game.sceneInfo;
            if (!sceneInfo) 
            {
                return;
            }
            try 
            {
                this.rebuildTileList(this._exitDataProvider, this._exitList, sceneInfo.passInfos, PassInfo);
                this.rebuildTileList(this._npcDataProvider, this._npcList, sceneInfo.npcInfos, NPCInfo);
                this.rebuildTileList(this._bossDataProvider, this._bossList, sceneInfo.bossRefreshs, BossRefreshInfo);
            }
            catch (e)
            {
                Log.debug(e);
            }
            return;
        }

        public reset(): void
        {
            this._hotTransferBtn.dispatchEvent(new Object /* flash.events.MouseEvent */(flash.events.MouseEvent.CLICK));
            this._autoCloseMap.selected = true;
            Cache.instance.mapui.autoCloseMap = this._autoCloseMap.selected;
            return;
        }

        /* internal  */rebuildTileList(arg1: DataProvider, arg2: TilePanel, arg3: Array<any>, arg4: Object): void
        {
            if (arg1) 
            {
                arg1.removeAll();
            }
            else 
            {
                arg1 = new DataProvider();
            }
            var loc1=0;
            var loc2=arg3.length;
            while (loc1 < loc2) 
            {
                if ((arg4 = arg3[loc1]) is NPCInfo) 
                {
                    if (!(arg4 as NPCInfo).isAddStage) 
                    {
                        ++loc1;
                        continue;
                    }
                }
                else if (typeof arg4 === "bossrefreshinfo") 
                {
                    if (!BossRule.isShowInMapUI(arg4 as BossRefreshInfo, this._currentMapid)) 
                    {
                        ++loc1;
                        continue;
                    }
                }
                arg1.addItem(arg4);
                ++loc1;
            }
            arg2.dataProvider = arg1;
            return;
        }

        /* internal  */onChangeHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.target.name != "hotTransferBtn") 
            {
                if (arg1.target.name == "commonTransferBtn") 
                {
                    DisplayUtil.removeMe(this._hotTransferSp);
                    this.addChild(this._commonTransferSp);
                }
            }
            else 
            {
                DisplayUtil.removeMe(this._commonTransferSp);
                this.addChild(this._hotTransferSp);
            }
            return;
        }

        /* internal  */onAutoCloseMapHandler(arg1: Object /* flash.events.Event */): void
        {
            Cache.instance.mapui.autoCloseMap = this._autoCloseMap.selected;
            return;
        }

        /* internal  */onVipHangBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._vipHangBtn.name != "hang") 
            {
                if (this._vipHangBtn.name == "back") 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.VIPHookQuit));
                }
            }
            else 
            {
                VIPUtil.toVipHookMap();
            }
            return;
        }

        public resetHangText(): void
        {
            if (this._vipHangBtn) 
            {
                if (GameMapUtil.isVIPHook(MapFileUtil.mapID)) 
                {
                    this._vipHangBtn.label = Language.getString(90326);
                    this._vipHangBtn.name = "back";
                }
                else 
                {
                    this._vipHangBtn.label = Language.getString(90327);
                    this._vipHangBtn.name = "hang";
                }
            }
            return;
        }

        protected /* var */_bg: ScaleBitmap;

        protected /* var */_mapExitBitmap: Object /* flash.display.Bitmap */;

        protected /* var */_exitList: TilePanel;

        protected /* var */_line1: Object /* flash.display.Bitmap */;

        protected /* var */_mapNpcBitmap: Object /* flash.display.Bitmap */;

        protected /* var */_npcList: TilePanel;

        protected /* var */_line2: Object /* flash.display.Bitmap */;

        protected /* var */_mapBossBitmap: Object /* flash.display.Bitmap */;

        protected /* var */_bossList: TilePanel;

        protected /* var */_npcDataProvider: DataProvider;

        protected /* var */_exitDataProvider: DataProvider;

        protected /* var */_bossDataProvider: DataProvider;

        /* internal */ /* var */_hotTransferSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_commonTransferSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_hotTransferBtn: GButton;

        /* internal */ /* var */_commonTransferBtn: GButton;

        /* internal */ /* var */_autoCloseMap: GCheckBox;

        /* internal */ /* var */_vipHangBtn: GButton;

        /* internal */ /* var */_currentMapid: int=0;
    }
